<!doctype html>
<html lang="zh">

<head>
	<!-- Required meta tags -->
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<meta name="keywords" content="山西农业大学,成绩查询">
	<meta name="description" content="山西农业大学成绩查询">
	<link rel="shortcut icon" href="./images/favicon.ico" />
	<link rel="bookmark" href="./images/favicon.ico" type="image/x-icon" />
	<link rel="stylesheet" href="./bootstrap/css/bootstrap.min.css" crossorigin="anonymous">
	<link rel="stylesheet" href="./css/main.css">
	<title>山西农业大学成绩查询</title>
</head>

<body>
	<div class="container">
		<nav class="navbar navbar-expand-md navbar-light fixed-top bg-white shadow-sm">
			<a class="navbar-brand text-dark" href="current_term.html">山西农业大学成绩查询</a>
			<button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#navbarCollapse"
				aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
				<span class="navbar-toggler-icon"></span>
			</button>
			<div class="navbar-collapse collapse" id="navbarCollapse">
				<ul class="navbar-nav mr-auto">
					<li class="nav-item">
						<a class="nav-link" href="current_term.html">本学期成绩</a>
					</li>
					<li class="nav-item active">
						<a class="nav-link" href="all_term.html">历年成绩</a>
					</li>
					<li class="nav-item">
						<a class="nav-link" href="fail.html">不及格成绩</a>
					</li>
				</ul>
				<ul class="navbar-nav">
					<li class="nav-item">
						<a class="nav-link" onclick="logout()" href="#">注销</a>
					</li>
				</ul>
			</div>
		</nav>
		<div class="row">
			<div class="col-md-8 offset-md-2">
				<div class="mt-2 mb-2">
					<div class="form-group row">
						<label for="selectTerm" class="col-lg-2 col-md-3 col-form-label">学期：</label>
						<div class="col-lg-6 col-md-7">
							<select type="email" class="form-control" id="selectTerm">
								<option>学期加载中......</option>
							</select>
						</div>
					</div>
					<div class="form-group row">
						<label for="courseNumber" class="col-lg-2 col-md-3 col-form-label">课程号：</label>
						<div class="col-lg-6 col-md-7">
							<input type="text" class="form-control" id="courseNumber">
						</div>
					</div>
					<div class="form-group row">
						<label for="courseName" class="col-lg-2 col-md-3 col-form-label">课程名：</label>
						<div class="col-lg-6 col-md-7">
							<input type="text" class="form-control" id="courseName">
						</div>
					</div>
					<div class="form-group row">
						<div class="col-lg-2 col-md-3">
							<button class="btn btn-primary form-control" id="search" onclick="search()"
								disabled>查询</button>
						</div>
					</div>
				</div>
				<div id="show" class="mt-2">
				</div>
			</div>
		</div>
	</div>


	<!-- Optional JavaScript -->
	<!-- jQuery first, then Popper.js, then Bootstrap JS -->
	<script src="./js/jquery.min.js" crossorigin="anonymous"></script>
	<script src="./js/popper.min.js" crossorigin="anonymous"></script>
	<script src="./js/bootstrap.min.js" crossorigin="anonymous"></script>
	<script type="text/javascript" src="./js/grade.js"></script>
	<script type="text/javascript">
		loadTerms();

		function loadTerms() {
			$.ajax({
				"url": "grade/terms_get.action",
				"method": "POST",
				"dataType": "json",
				"success": function (data) {
					if (data['status'] === -2) {
						alert(data['data']);
						window.location.href = "login.html";
						return;
					}
					if (data['status'] !== 1) {
						alert(data['data'] + "刷新页面重试");
						location.reload();
						return;
					}
					showTerms(data['data'], $("#selectTerm"), function () {
						disableButton($("#search"), false);
					});
				},
				"error": function () {
					alert("成绩加载失败，刷新页面重试");
					location.reload();
				}
			})
		}


		function search() {
			let termId = $("#selectTerm").val();
			let courseNumber = $("#courseNumber").val();
			let courseName = $("#courseName").val();
			$("#show").html("正在加载呀......");

			disableButton($("#search"), true);

			$.ajax({
				"url": "grade/all_term.action",
				"method": "POST",
				"data": {
					"termId": termId,
					"courseNumber": courseNumber,
					"courseName": courseName
				},
				"dataType": "json",
				"success": function (data) {
					if (data['status'] === -2) {
						alert(data['data']);
						window.location.href = "login.html";
						return;
					}
					if (data['status'] !== 1) {
						alert(data['data']);
						return;
					}
					showGrade(data['data'], $("#show"), function () {
						disableButton($("#search"), false);
					});
				},
				"error": function () {
					alert("成绩获取失败");
					window.location.reload();
				}
			})
		}
	</script>
</body>

</html>